package cn.tedu.csmall.passport.controller;

import cn.tedu.csmall.passport.pojo.vo.RolelistVO;
import cn.tedu.csmall.passport.security.LoginPrincipal;
import cn.tedu.csmall.passport.service.IRoleService;
import cn.tedu.csmall.passport.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.vote.RoleVoter;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Api(tags = "02. 角色管理")
@Slf4j
@RestController
@RequestMapping("/roles")
public class RoleController {
    @Autowired
    private IRoleService service;
    @ApiOperation("角色列表")
    @ApiOperationSupport(order = 200)
    @GetMapping("")
    public JsonResult <List<RolelistVO>> get(@ApiIgnore @AuthenticationPrincipal LoginPrincipal loginPrincipal){
        log.debug("开始查询角色数据");
        log.debug("当事人id:{}",loginPrincipal.getId());
        log.debug("当事人username:{}",loginPrincipal.getUsername());
        List<RolelistVO> roleList = service.getRoleList();
        return JsonResult.ok(roleList);
    }
}
